<?php
namespace app\common\formula;

// 量表算法计算

use app\model\UserModel;

class Formula
{
    /**
     * 求和（总分）
     * @param $relatedQuestionArr
     * @param $questionScoreArr
     * @param $formula
     * @return float
     */
    public function formula1($relatedQuestionArr, $questionScoreArr,$formula): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value) {
            $score += $questionScoreArr[$value['num']]['score']??0;
        }
        return (float)number_format($score, 2);
    }

    /**
     * 计算总分然后除以系数（均分）
     * @param $relatedQuestionArr
     * @param $questionScoreArr
     * @param $formula
     * @return float
     */
    public function formula2($relatedQuestionArr, $questionScoreArr,$formula): float
    {
        //解析算法，【这里是找到"/"之后得所有数值】
//        $formula = matchNumberAfterSlash($formula);
//        if(empty($formula)) exit(error("算法错误，请联系管理员！"));
        $score = 0;
        $keys = 0;
        foreach ($relatedQuestionArr as $value) {
            $score += $questionScoreArr[$value['num']]['score']??0;
            $keys += 1;
        }
        $score = $score/$keys;
        $score = round($score,2);
        return (float)number_format($score, 2);
    }

    public function formula3($relatedQuestionArr, $questionScoreArr, $formula): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value) {
            if($questionScoreArr[$value['num']]['score'] >=2 && $questionScoreArr[$value['num']]['score'] <=5){
                $score += 1;
            }
        }
        return (float)number_format($score, 2);
    }

    public function formula4($relatedQuestionArr, $questionScoreArr, $formula): float
    {
        $totalScore = 0;//总分
        $positiveScore = 0;//阳性项目数
        foreach ($relatedQuestionArr as $value) {
            //阳性总分
            if($questionScoreArr[$value['num']]['score'] >=2 && $questionScoreArr[$value['num']]['score'] <=5){
                $positiveScore += 1;
            }
            //总分
            $totalScore += $questionScoreArr[$value['num']]['score']??0;
        }
        $negativeScore = count($relatedQuestionArr)-$positiveScore;//阴性项目数(或总分)
        $positiveScore = $positiveScore == 0 ? 1 : $positiveScore;
        $score = ($totalScore-$negativeScore)/$positiveScore;
        return (float)number_format($score, 2);
    }

    public function formula5($relatedQuestionArr, $questionScoreArr, $formula): float
    {
        //解析算法，【这里是找到"*"之后得所有数值】
        $formula = matchNumberMultiplication($formula);
        if(empty($formula)){
            exit(error("算法错误，请联系管理员！"));
        }
        $totalScore = 0;//总分
        if(count($questionScoreArr)>0){
            foreach ($relatedQuestionArr as $value) {
                //总分
                $totalScore += $questionScoreArr[$value['num']]['score']??0;
            }
        }
        $score = $totalScore*$formula;
        $score = round($score,2);
        return (float)number_format($score, 2);
    }

    public function formula6($relatedQuestionArr, $questionScoreArr, $formula): float
    {
        //解析算法，【这里是找到"*"之后得所有数值】
        $formula = matchNumberMultiplication($formula);
        if(empty($formula)){
            exit(error("算法错误，请联系管理员！"));
        }
        $totalScore = 0;//总分
        if(count($questionScoreArr)>0){
            foreach ($relatedQuestionArr as $value) {
                //总分
                $totalScore += $questionScoreArr[$value['num']]['score']??0;
            }
        }
        $score = $totalScore*$formula;
        $score = round($score);
        return (float)number_format($score);
    }

    public function formula7($relatedQuestionArr, $questionScoreArr, $formula): float
    {
        $totalScoreA = 0; // 成分A+成分C+成分F【单个题目的得分总和】
        $totalScoreB = 0; // 成分B【多个题目的总分】
        $totalScoreC = 0; // 成分D
        $totalScoreD = 0; // 成分E
        $totalScoreE = 0; // 成分G

        // 预先准备好所需的数据
        $questionScore = array_column($questionScoreArr, 'score', 'num');
        $relatedQuestions = array_column($relatedQuestionArr, null, 'num');
        if (count($relatedQuestions) > 0) {
            foreach ($relatedQuestions as $num => $value) {
                switch ($num) {
                    case '15':
                    case '4':
                    case '16':
                        // 成分A
                        $totalScoreA += $questionScore[$num] ?? 0;
                        break;

                    case '2':
                        // 成分B
                        $totalScoreB = ($questionScore[2] ?? 0) + ($questionScore[5] ?? 0);
                        break;

                    case '1':
                        // 成分D
                        $score4 = $questionScore[4] ?? 0;
                        $score3 = $questionScore[3] ?? 0;
                        $score1 = $questionScore[1] ?? 0;
                        if ($score3 != $score1) {
                            $temp_totalScore = intval($score4 / ($score3 - $score1) * 100);
                            if ($temp_totalScore >= 85) {
                                $totalScoreC = 0;
                            } elseif ($temp_totalScore >= 75) {
                                $totalScoreC = 1;
                            } elseif ($temp_totalScore >= 65) {
                                $totalScoreC = 2;
                            } else {
                                $totalScoreC = 0;
                            }
                        }
                        break;

                    case '6':
                        // 成分E
                        $totalScoreD = 0;
                        for ($i = 6; $i <= 14; $i++) {
                            $totalScoreD += $questionScore[$i] ?? 0;
                        }
                        if ($totalScoreD == 0) {
                            $totalScoreD = 0;
                        } elseif ($totalScoreD <= 9) {
                            $totalScoreD = 1;
                        } elseif ($totalScoreD <= 18) {
                            $totalScoreD = 2;
                        } else {
                            $totalScoreD = 3;
                        }
                        break;

                    case '17':
                        // 成分G
                        $totalScoreE = 0;
                        $one = $questionScore[17] ?? 0;
                        $two = $questionScore[18] ?? 0;
                        $totalScoreE = $one + $two;
                        if ($totalScoreE == 0) {
                            $totalScoreE = 0;
                        } elseif ($totalScoreE <= 2) {
                            $totalScoreE = 1;
                        } elseif ($totalScoreE <= 4) {
                            $totalScoreE = 2;
                        } else {
                            $totalScoreE = 3;
                        }
                        break;
                }
            }
        }

        $score = $totalScoreA + $totalScoreB + $totalScoreC + $totalScoreD + $totalScoreE;
        return (float)number_format($score);
    }


    public function formula8($relatedQuestionArr, $questionScoreArr, $formula): float
    {
        //获取对应因子的题号
        $titleList['title'] = [
            [1,8,15,22,29,36,43,50,57,64],
            [2,9,16,23,30,37,44,51,58,65],
            [3,10,17,24,31,38,45,52,59,66],
            [4,11,18,25,32,39,46,53,60,67],
            [5,12,19,26,33,40,47,54,61,68],
            [6,13,20,27,34,41,48,55,62,69],
        ];
        //初始化每个因子的得分
        $titleList['score'] = [
            0,0,0,0,0,0,
        ];
        //得分对应的范围
        $titleList['end_score'] = [
            ['rang'=>[0,4],'score'=>1],
            ['rang'=>[5,8],'score'=>2],
            ['rang'=>[9,12],'score'=>3],
            ['rang'=>[13,16],'score'=>4],
            ['rang'=>[17,20],'score'=>5],
        ];
        //初始化得分对应的最后得分
        $titleList['total'] = [
            0,0,0,0,0,0,
        ];
        //初始化系数
        $titleList['coefficient'] = 3;
        //开始计算
        $questionScore = array_column($questionScoreArr, 'score', 'num');
        $relatedQuestions = array_column($relatedQuestionArr, null, 'num');
        if (count($relatedQuestions) > 0) {
            foreach($titleList['title'] as $kk=>$vv){
                foreach ($relatedQuestions as $num => $value) {
                    if(in_array($num,$vv)){
                        $titleList['score'][$kk] += $questionScore[$num];
                    }
                }
            }
        }
        //得出最后得分
        foreach($titleList['score'] as $kk=>$vv){
            foreach($titleList['end_score'] as $value){
                //判断初始得分是否在范围内
                if($vv>=$value['rang']['0'] && $vv<= $value['rang']['1']){
                    $titleList['total'][$kk] = $value['score'];
                }
            }
        }
        $score = array_sum($titleList['total'])*$titleList['coefficient'];
        return (float)number_format($score);
    }

    public function formula9($relatedQuestionArr, $questionScoreArr, $formula): float
    {
        $array['A'] = 0;//选A的次数
        $array['B'] = 0;//选B的次数
        $array['C'] = 0;//选C的次数
        $array['D'] = 0;//选D的次数
        //开始计算
        $questionScore = array_column($questionScoreArr, 'score', 'num');
        $relatedQuestions = array_column($relatedQuestionArr, null, 'num');
        if (count($relatedQuestions) > 0) {
            foreach ($questionScore as $num => $value) {
                switch ($value){
                    case '1':
                        $array['C'] +=1;
                        break;
                    case '2':
                        $array['B'] +=1;
                        break;
                    case '3':
                        $array['A'] +=1;
                        break;
                    default:
                        $array['D'] =0;
                        break;
                }
            }
        }
        $score = 3*$array['A']+2*$array['B']+$array['C']+$array['D'];
        return (float)number_format($score);
    }

    public function formula10($relatedQuestionArr, $questionScoreArr, $formula): float
    {
        //解析算法，【这里是找到"/"之后得所有数值】
        $keyOne = matchNumberAfterSlash($formula);
        if(empty($keyOne)){
            exit(error("算法错误，请联系管理员！"));
        }
        $keyTwo = matchNumberMultiplication($formula);
        if(empty($keyTwo)){
            exit(error("算法错误，请联系管理员！"));
        }
        $score = 0;
        foreach ($relatedQuestionArr as $value) {
            $score += $questionScoreArr[$value['num']]['score'];
        }
        $score = $score/$keyOne*$keyTwo;
        $score = round($score,2);
        return (float)number_format($score, 2);
    }

    public function formula12($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value) {
            $score += $questionScoreArr[$value['num']]['score'];
        }
        $name = '';
        //第一个因子（L）到（Q）
        switch ($formula){
            case 'sum(3,7,12,15,23,30,32,35,39,43,47,51,53,55,59,60,66,77)（筛选是男童/女童，对应T分）':
                //说谎（L）
                $name = "精神质(P)";
                break;
            case 'sum(1,5,9,13,17,19,21,25,28,33,37,41,45,49,57,61,64,68,71,75,79,83,85,86,88)（筛选是男童/女童，对应T分）':
                //诈病（F）
                $name = "内外向(E)";
                break;
            case 'sum(2,6,10,14,18,22,26,29,34,38,42,46,50,54,58,62,65,69,72,74,76,81,84)（筛选是男童/女童，对应T分）':
                //校正（K）
                $name = "情绪稳定性(N)";
                break;
            case 'sum(4,8,11,16,20,24,27,31,36,40,44,48,52,56,63,67,70,73,78,80,82,87)（筛选是男童/女童，对应T分）':
                //疑病(Hs)
                $name = "掩饰(L)";
                break;
        }
        $scored = $this->getConvertedScore12($uid,$score,$name);
        return (float)number_format($scored, 2);
    }


    private function getConvertedScore12($uid, $score,$name)
    {

        // 合并的映射数组
        $scoreMappings = [
            'male' => [
                '精神质(P)' => [
                    '7'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 45, 4 => 45, 5 => 50, 6 => 55, 7 => 55, 8 => 60, 9 => 65,
                        10 => 65, 11 => 70, 12 => 75, 13 => 80, 14 => 80, 15 => 85, 16 => 90, 17 => 90,
                        'default' => 91,
                    ],
                    '8'=>[
                        0 => 39, 1 => 40, 2 => 40, 3 => 45, 4 => 50, 5 => 50, 6 => 55, 7 => 60, 8 => 60, 9 => 65,
                        10 => 70, 11 => 70, 12 => 75, 13 => 80, 14 => 80, 15 => 85, 16 => 90, 17 => 90,
                        'default' => 91,
                    ],
                    '9'=>[
                        0 => 39, 1 => 40, 2 => 40, 3 => 45, 4 => 50, 5 => 50, 6 => 55, 7 => 55, 8 => 60, 9 => 65,
                        10 => 65, 11 => 70, 12 => 70, 13 => 75, 14 => 80, 15 => 80, 16 => 85,
                        'default' => 86,
                    ],
                    '10'=>[
                        0 => 39, 1 => 40, 2 => 40, 3 => 45, 4 => 50, 5 => 50, 6 => 55, 7 => 60, 8 => 65, 9 => 65,
                        10 => 70, 11 => 75, 12 => 75, 13 => 80, 14 => 85, 15 => 90, 16 => 90,
                        'default' => 91,
                    ],
                    '11'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 45, 5 => 50, 6 => 50, 7 => 55, 8 => 60, 9 => 65,
                        10 => 65, 11 => 70, 12 => 75, 13 => 75, 14 => 80, 15 => 85, 16 => 85, 17 => 90,
                        'default' => 91,
                    ],
                    '12'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 45, 5 => 50, 6 => 50, 7 => 55, 8 => 60, 9 => 60,
                        10 => 65, 11 => 70, 12 => 70, 13 => 75, 14 => 80, 15 => 85, 16 => 85, 17 => 90,
                        'default' => 91,
                    ],
                    '13'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 45, 4 => 45, 5 => 50, 6 => 50, 7 => 55, 8 => 60, 9 => 60,
                        10 => 65, 11 => 65, 12 => 70, 13 => 75, 14 => 75, 15 => 80, 16 => 80, 17 => 85,
                        'default' => 86,
                    ],
                    '14'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 40, 4 => 45, 5 => 50, 6 => 50, 7 => 55, 8 => 60, 9 => 60,
                        10 => 65, 11 => 70, 12 => 70, 13 => 75, 14 => 80, 15 => 85, 16 => 85, 17 => 90,
                        'default' => 91,
                    ],
                    '15'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 45, 4 => 45, 5 => 50, 6 => 55, 7 => 55, 8 => 60, 9 => 65,
                        10 => 65, 11 => 70, 12 => 75, 13 => 80, 14 => 80, 15 => 85, 16 => 90, 17 => 90,
                        'default' => 91,
                    ],
                ],
                '内外向(E)' => [
                    '7'=>[
                        0 => 14, 1 => 15, 2 => 15, 3 => 20, 4 => 20,5 => 25, 6 => 25, 7 => 30, 8 => 30, 9 => 35,
                        10 => 35, 11 => 40, 12 => 40, 13 => 45, 14 => 45,15 => 50, 16 => 50, 17 => 55, 18 => 55, 19 => 60,
                        20 => 60, 21 => 65, 22 => 65, 23 => 70, 24 => 70,
                        'default' => 71,
                    ],
                    '8'=>[
                        0 => 9, 1 => 10, 2 => 15, 3 => 15, 4 => 20,5 => 20, 6 => 25, 7 => 25, 8 => 30, 9 => 30,
                        10 => 35, 11 => 35, 12 => 35, 13 => 40, 14 => 40, 15 => 45, 16 => 45, 17 => 50, 18 => 50, 19 => 55,
                        20 => 55, 21 => 60, 22 => 65, 23 => 65, 24 => 65,
                        'default' => 66,
                    ],
                    '9'=>[
                        0 => 0, 1 => 0, 2 => 5, 3 => 10, 4 => 10 ,5 => 15, 6 => 15, 7 => 20, 8 => 25, 9 => 25,
                        10 => 30, 11 => 30 , 12 => 35, 13 => 40, 14 => 40 ,15 => 45, 16 => 45, 17 => 50, 18 => 55, 19 => 55,
                        20 => 60, 21 => 60 , 22 => 65, 23 => 65, 24 => 70,
                        'default' => 71,
                    ],
                    '10'=>[
                        0 => 0, 1 => 0, 2 => 5, 3 => 5, 4 => 10 ,5 => 15, 6 => 15, 7 => 20, 8 => 20, 9 => 25,
                        10 => 25, 11 => 30 , 12 => 30, 13 => 35, 14 => 40 ,15 => 40, 16 => 45, 17 => 45, 18 => 50, 19 => 50,
                        20 => 55, 21 => 55 , 22 => 60, 23 => 65, 24 => 65,
                        'default' => 66,
                    ],
                    '11'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0 ,5 => 5, 6 => 5, 7 => 10, 8 => 15, 9 => 15,
                        10 => 20, 11 => 25 , 12 => 25, 13 => 30, 14 => 35 ,15 => 35, 16 => 40, 17 => 45, 18 => 45, 19 => 50,
                        20 => 55, 21 => 55 , 22 => 60, 23 => 65, 24 => 65,
                        'default' => 66,
                    ],
                    '12'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 5, 4 => 5 ,5 => 5, 6 => 10, 7 => 15, 8 => 15, 9 => 20,
                        10 => 20, 11 => 25 , 12 => 30, 13 => 30, 14 => 35 ,15 => 35, 16 => 40, 17 => 45, 18 => 45, 19 => 50,
                        20 => 55, 21 => 55 , 22 => 60, 23 => 60, 24 => 65,
                        'default' => 66,
                    ],
                    '13'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 5, 4 => 5 ,5 => 5, 6 => 10, 7 => 15, 8 => 15, 9 => 20,
                        10 => 20, 11 => 25 , 12 => 30, 13 => 30, 14 => 35 ,15 => 40, 16 => 40, 17 => 45, 18 => 50, 19 => 50,
                        20 => 55, 21 => 55 , 22 => 60, 23 => 65, 24 => 65,
                        'default' => 66,
                    ],
                    '14'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 5, 4 => 5 ,5 => 10, 6 => 15, 7 => 15, 8 => 20, 9 => 20,
                        10 => 25, 11 => 30 , 12 => 30, 13 => 35, 14 => 35 ,15 => 40, 16 => 45, 17 => 45, 18 => 50, 19 => 50,
                        20 => 55, 21 => 60 , 22 => 60, 23 => 65, 24 => 65,
                        'default' => 66,
                    ],
                    '15'=>[
                        0 => 9, 1 => 10, 2 => 15, 3 => 15, 4 => 20 ,5 => 20, 6 => 25, 7 => 25, 8 => 30, 9 => 30,
                        10 => 35, 11 => 35 , 12 => 40, 13 => 40, 14 => 45 ,15 => 45, 16 => 45, 17 => 50, 18 => 50, 19 => 55,
                        20 => 55, 21 => 60 , 22 => 60, 23 => 65, 24 => 65,
                        'default' => 66,
                    ],
                ],
                '情绪稳定性(N)' => [
                    '7'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 40,5 => 45, 6 => 45, 7 => 50, 8 => 50, 9 => 55,
                        10 => 55, 11 => 60, 12 => 60, 13 => 65, 14 => 65, 15 => 65, 16 => 70, 17 => 70, 18 => 75, 19 => 75,
                        20 => 80, 21 => 80, 22 => 85, 23 => 85,
                        'default' => 86,
                    ],
                    '8'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 45, 5 => 45, 6 => 50, 7 => 50, 8 => 55, 9 => 55,
                        10 => 60, 11 => 60, 12 => 65, 13 => 65, 14 => 70, 15 => 70, 16 => 75, 17 => 75, 18 => 80, 19 => 80,
                        20 => 85, 21 => 85, 22 => 90, 23 => 90,
                        'default' => 91,
                    ],
                    '9'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 40, 4 => 40 ,5 => 45, 6 => 45, 7 => 50, 8 => 50, 9 => 50,
                        10 => 55, 11 => 55 , 12 => 60, 13 => 60, 14 => 65 ,15 => 65, 16 => 70, 17 => 70, 18 => 70, 19 => 75,
                        20 => 75, 21 => 80 , 22 => 80, 23 => 85,
                        'default' => 86,
                    ],
                    '10'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 40 ,5 => 45, 6 => 45, 7 => 50, 8 => 50, 9 => 55,
                        10 => 55, 11 => 55 , 12 => 60, 13 => 60, 14 => 65 ,15 => 65, 16 => 70, 17 => 70, 18 => 75, 19 => 75,
                        20 => 75, 21 => 80 , 22 => 80, 23 => 85,
                        'default' => 86,
                    ],
                    '11'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 40 ,5 => 45, 6 => 45, 7 => 45, 8 => 50, 9 => 50,
                        10 => 55, 11 => 55 , 12 => 60, 13 => 60, 14 => 65 ,15 => 65, 16 => 65, 17 => 70, 18 => 70, 19 => 75,
                        20 => 75, 21 => 80 , 22 => 80, 23 => 85,
                        'default' => 86,
                    ],
                    '12'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 40, 4 => 40 ,5 => 45, 6 => 45, 7 => 50, 8 => 50, 9 => 50,
                        10 => 55, 11 => 55 , 12 => 60, 13 => 60, 14 => 60 ,15 => 65, 16 => 65, 17 => 70, 18 => 70, 19 => 75,
                        20 => 75, 21 => 75 , 22 => 80, 23 => 80,
                        'default' => 81,
                    ],
                    '13'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 40, 4 => 40 ,5 => 45, 6 => 45, 7 => 45, 8 => 50, 9 => 50,
                        10 => 55, 11 => 55 , 12 => 55, 13 => 60, 14 => 60 ,15 => 60, 16 => 65, 17 => 65, 18 => 70, 19 => 70,
                        20 => 70, 21 => 75 , 22 => 75, 23 => 80,
                        'default' => 81,
                    ],
                    '14'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 35, 4 => 40 ,5 => 40, 6 => 45, 7 => 45, 8 => 45, 9 => 50,
                        10 => 50, 11 => 55 , 12 => 55, 13 => 60, 14 => 60 ,15 => 60, 16 => 65, 17 => 65, 18 => 70, 19 => 70,
                        20 => 70, 21 => 75 , 22 => 75, 23 => 80,
                        'default' => 81,
                    ],
                    '15'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 40, 4 => 40 ,5 => 40, 6 => 45, 7 => 45, 8 => 50, 9 => 50,
                        10 => 50, 11 => 55 , 12 => 55, 13 => 60, 14 => 60 ,15 => 60, 16 => 65, 17 => 65, 18 => 70, 19 => 70,
                        20 => 70, 21 => 75 , 22 => 75, 23 => 80,
                        'default' => 81,
                    ],
                ],
                '掩饰(L)' => [
                    '7'=>[
                        0 => 14, 1 => 15, 2 => 15, 3 => 20, 4 => 20, 5 => 25, 6 => 25, 7 => 30, 8 => 30, 9 => 35,
                        10 => 35, 11 => 40, 12 => 40, 13 => 45, 14 => 50, 15 => 50, 16 => 55, 17 => 55, 18 => 60, 19 => 60,
                        20 => 65, 21 => 65, 22 => 70,
                        'default' => 71,
                    ],
                    '8'=>[
                        0 => 9, 1 => 10, 2 => 10, 3 => 15, 4 => 15, 5 => 20, 6 => 25, 7 => 25, 8 => 30, 9 => 30,
                        10 => 35, 11 => 40, 12 => 40, 13 => 45, 14 => 45, 15 => 50, 16 => 50, 17 => 55, 18 => 60, 19 => 60,
                        20 => 65, 21 => 65, 22 => 70,
                        'default' => 71,
                    ],
                    '9'=>[
                        0 => 24, 1 => 25, 2 => 30, 3 => 30, 4 => 30 ,5 => 35, 6 => 35, 7 => 35, 8 => 40, 9 => 40,
                        10 => 45, 11 => 45 , 12 => 45, 13 => 50, 14 => 50 ,15 => 55, 16 => 55, 17 => 55, 18 => 60, 19 => 60,
                        20 => 60, 21 => 65 , 22 => 65,
                        'default' => 66,
                    ],
                    '10'=>[
                        0 => 19, 1 => 20, 2 => 25, 3 => 25, 4 => 30 ,5 => 30, 6 => 30, 7 => 35, 8 => 35, 9 => 40,
                        10 => 40, 11 => 45 , 12 => 45, 13 => 45, 14 => 50 ,15 => 50, 16 => 55, 17 => 55, 18 => 60, 19 => 60,
                        20 => 60, 21 => 65 , 22 => 65,
                        'default' => 66,
                    ],
                    '11'=>[
                        0 => 19, 1 => 20, 2 => 25, 3 => 25, 4 => 30 ,5 => 30, 6 => 35, 7 => 35, 8 => 40, 9 => 40,
                        10 => 45, 11 => 45 , 12 => 50, 13 => 50, 14 => 55 ,15 => 55, 16 => 60, 17 => 60, 18 => 65, 19 => 65,
                        20 => 70, 21 => 75 , 22 => 75,
                        'default' => 76,
                    ],
                    '12'=>[
                        0 => 19, 1 => 20, 2 => 25, 3 => 25, 4 => 30 ,5 => 30, 6 => 35, 7 => 35, 8 => 40, 9 => 40,
                        10 => 45, 11 => 45 , 12 => 50, 13 => 50, 14 => 55 ,15 => 55, 16 => 60, 17 => 60, 18 => 65, 19 => 65,
                        20 => 70, 21 => 70 , 22 => 75,
                        'default' => 76,
                    ],
                    '13'=>[
                        0 => 24, 1 => 25, 2 => 25, 3 => 30, 4 => 30 ,5 => 35, 6 => 35, 7 => 40, 8 => 40, 9 => 45,
                        10 => 45, 11 => 45 , 12 => 50, 13 => 50, 14 => 55 ,15 => 55, 16 => 60, 17 => 60, 18 => 65, 19 => 65,
                        20 => 70, 21 => 70 , 22 => 75,
                        'default' => 76,
                    ],
                    '14'=>[
                        0 => 24, 1 => 25, 2 => 25, 3 => 25, 4 => 30 ,5 => 30, 6 => 35, 7 => 35, 8 => 40, 9 => 40,
                        10 => 45, 11 => 45 , 12 => 45, 13 => 50, 14 => 50 ,15 => 55, 16 => 55, 17 => 60, 18 => 60, 19 => 60,
                        20 => 65, 21 => 65 , 22 => 70,
                        'default' => 71,
                    ],
                    '15'=>[
                        0 => 24, 1 => 25, 2 => 30, 3 => 30, 4 => 30 ,5 => 35, 6 => 35, 7 => 40, 8 => 40, 9 => 45,
                        10 => 45, 11 => 45 , 12 => 50, 13 => 50, 14 => 55 ,15 => 55, 16 => 55, 17 => 60, 18 => 60, 19 => 65,
                        20 => 65, 21 => 65 , 22 => 70,
                        'default' => 71,
                    ],
                ],
            ],
            'female' => [
                '精神质(P)' => [
                    '7'=>[
                        0 => 39, 1 => 40, 2 => 45, 3 => 50, 4 => 50, 5 => 55, 6 => 60, 7 => 65, 8 => 65, 9 => 70,
                        10 => 75, 11 => 80, 12 => 80, 13 => 85, 14 => 90, 15 => 95, 16 => 95, 17 => 100, 18 => 105,
                        'default' => 106,
                    ],
                    '8'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 45, 4 => 50, 5 => 55, 6 => 60, 7 => 65, 8 => 70, 9 => 75,
                        10 => 80, 11 => 85, 12 => 90, 13 => 95, 14 => 100, 15 => 105, 16 => 110, 17 => 115,
                        'default' => 120,
                    ],
                    '9'=>[
                        0 => 39, 1 => 40, 2 => 45, 3 => 50, 4 => 50, 5 => 65, 6 => 70, 7 => 75, 8 => 80, 9 => 85,
                        10 => 90, 11 => 95, 12 => 100, 13 => 105, 14 => 110, 15 => 115,
                        'default' => 120,
                    ],
                    '10'=>[
                        0 => 39, 1 => 40, 2 => 45, 3 => 50, 4 => 55, 5 => 60, 6 => 65, 7 => 65, 8 => 70, 9 => 75,
                        10 => 80, 11 => 85, 12 => 90, 13 => 95, 14 => 100, 15 => 105, 16 => 110, 17 => 115, 18 => 115,
                        'default' => 120,
                    ],
                    '11'=>[
                        0 => 39, 1 => 40, 2 => 45, 3 => 50, 4 => 50, 5 => 55, 6 => 60, 7 => 65, 8 => 65, 9 => 70,
                        10 => 75, 11 => 75, 12 => 80, 13 => 85, 14 => 85, 15 => 90, 16 => 95, 17 => 95, 18 => 100,
                        'default' => 101,
                    ],
                    '12'=>[
                        0 => 39, 1 => 40, 2 => 45, 3 => 50, 4 => 55, 5 => 60, 6 => 65, 7 => 70, 8 => 75, 9 => 80,
                        10 => 85, 11 => 90, 12 => 90, 13 => 95, 14 => 100, 15 => 105, 16 => 110, 17 => 115,
                        'default' => 120,
                    ],
                    '13'=>[
                        0 => 39, 1 => 40, 2 => 45, 3 => 45, 4 => 50, 5 => 55, 6 => 55, 7 => 60, 8 => 65, 9 => 70,
                        10 => 70, 11 => 75, 12 => 80, 13 => 80, 14 => 85, 15 => 90, 16 => 95, 17 => 95, 18 => 100,
                        'default' => 101,
                    ],
                    '14'=>[
                        0 => 39, 1 => 40, 2 => 45, 3 => 50, 4 => 50, 5 => 55, 6 => 60, 7 => 65, 8 => 70, 9 => 75,
                        10 => 75, 11 => 80, 12 => 85, 13 => 90, 14 => 95, 15 => 100, 16 => 100, 17 => 105, 18 => 110,
                        'default' => 111,
                    ],
                    '15'=>[
                        0 => 39, 1 => 40, 2 => 45, 3 => 50, 4 => 50, 5 => 55, 6 => 60, 7 => 65, 8 => 70, 9 => 75,
                        10 => 80, 11 => 85, 12 => 85, 13 => 90, 14 => 95, 15 => 100, 16 => 105, 17 => 110, 18 => 115,
                        'default' => 116,
                    ],
                ],
                '内外向(E)' => [
                    '7'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 2, 7 => 10, 8 => 10, 9 => 15,
                        10 => 20, 11 => 25, 12 => 30, 13 => 30 , 14 => 35, 15 => 40, 16 => 45, 17 => 50, 18 => 55, 19 => 55,
                        20 => 60, 21 => 65, 22 => 70, 23 => 75, 24 => 75, 25 => 80,
                        'default' => 81,
                    ],
                    '8'=>[
                        0 => 4, 1 => 5, 2 => 5, 3 => 10, 4 => 10, 5 => 15, 6 => 20, 7 => 20, 8 => 25, 9 => 25,
                        10 => 30, 11 => 30, 12 => 35, 13 => 40, 14 => 40, 15 => 45, 16 => 45, 17 => 50, 18 => 50, 19 => 55,
                        20 => 60, 21 => 60, 22 => 65, 23 => 65, 24 => 70, 25 => 70,
                        'default' => 71,
                    ],
                    '9'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 5, 4 => 5 ,5 => 10, 6 => 15, 7 => 15, 8 => 20, 9 => 25,
                        10 => 25, 11 => 30 , 12 => 35, 13 => 35, 14 => 40 ,15 => 40, 16 => 45, 17 => 50, 18 => 50, 19 => 55,
                        20 => 60, 21 => 60 , 22 => 65, 23 => 70, 24 => 70, 25 => 75,
                        'default' => 76,
                    ],
                    '10'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0 ,5 => 5, 6 => 5, 7 => 10, 8 => 15, 9 => 15,
                        10 => 20, 11 => 25 , 12 => 30, 13 => 30, 14 => 35 ,15 => 40, 16 => 40, 17 => 45, 18 => 50, 19 => 50,
                        20 => 55, 21 => 60 , 22 => 60, 23 => 65, 24 => 70, 25 => 70,
                        'default' => 71,
                    ],
                    '11'=>[
                        0 => 9, 1 => 10, 2 => 10, 3 => 15, 4 => 15 ,5 => 20, 6 => 20, 7 => 25, 8 => 25, 9 => 30,
                        10 => 30, 11 => 35 , 12 => 35, 13 => 40, 14 => 40 ,15 => 45, 16 => 45, 17 => 50, 18 => 50, 19 => 55,
                        20 => 55, 21 => 60 , 22 => 60, 23 => 65, 24 => 65, 25 => 70,
                        'default' => 71,
                    ],
                    '12'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 5, 4 => 5 ,5 => 5, 6 => 10, 7 => 15, 8 => 15, 9 => 20,
                        10 => 20, 11 => 25 , 12 => 30, 13 => 30, 14 => 35 ,15 => 40, 16 => 40, 17 => 45, 18 => 50, 19 => 50,
                        20 => 55, 21 => 60 , 22 => 60, 23 => 65, 24 => 65, 25 => 70,
                        'default' => 71,
                    ],
                    '13'=>[
                        0 => 9, 1 => 10, 2 => 10, 3 => 15, 4 => 15 ,5 => 20, 6 => 20, 7 => 25, 8 => 25, 9 => 30,
                        10 => 30, 11 => 35 , 12 => 35, 13 => 40, 14 => 40 ,15 => 45, 16 => 45, 17 => 50, 18 => 50, 19 => 55,
                        20 => 55, 21 => 60 , 22 => 60, 23 => 65, 24 => 65, 25 => 70,
                        'default' => 71,
                    ],
                    '14'=>[
                        0 => 14, 1 => 15, 2 => 15, 3 => 20, 4 => 20 ,5 => 25, 6 => 25, 7 => 25, 8 => 30, 9 => 30,
                        10 => 35, 11 => 35 , 12 => 40, 13 => 40, 14 => 45 ,15 => 45, 16 => 50, 17 => 50, 18 => 55, 19 => 55,
                        20 => 55, 21 => 60 , 22 => 60, 23 => 65, 24 => 65, 25 => 70,
                        'default' => 71,
                    ],
                    '15'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 5, 4 => 5 ,5 => 10, 6 => 15, 7 => 15, 8 => 20, 9 => 20,
                        10 => 25, 11 => 30 , 12 => 30, 13 => 35, 14 => 35 ,15 => 40, 16 => 45, 17 => 45, 18 => 50, 19 => 55,
                        20 => 55, 21 => 60 , 22 => 60, 23 => 65, 24 => 70, 25 => 75,
                        'default' => 76,
                    ],
                ],
                '情绪稳定性(N)' => [
                    '7'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 45, 5 => 50, 6 => 50, 7 => 55, 8 => 55, 9 => 60,
                        10 => 60, 11 => 65, 12 => 65, 13 => 70, 14 => 70, 15 => 75, 16 => 80, 17 => 80, 18 => 85, 19 => 85,
                        20 => 90, 21 => 90, 22 => 95, 23 => 95,
                        'default' => 96,
                    ],
                    '8'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 45, 5 => 45, 6 => 50, 7 => 50, 8 => 55, 9 => 55,
                        10 => 60, 11 => 60, 12 => 65, 13 => 65, 14 => 70, 15 => 70, 16 => 75, 17 => 75, 18 => 80, 19 => 80,
                        20 => 85, 21 => 85, 22 => 90, 23 => 90,
                        'default' => 91,
                    ],
                    '9'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 40, 4 => 40, 5 => 45, 6 => 45, 7 => 50, 8 => 50, 9 => 50,
                        10 => 55, 11 => 55 , 12 => 60, 13 => 60, 14 => 60, 15 => 65, 16 => 65, 17 => 70, 18 => 70, 19 => 75,
                        20 => 75, 21 => 80 , 22 => 80, 23 => 80,
                        'default' => 81,
                    ],
                    '10'=>[
                        0 => 34, 1 => 35, 2 => 40, 3 => 40, 4 => 45, 5 => 45, 6 => 50, 7 => 50, 8 => 55, 9 => 55,
                        10 => 55, 11 => 60 , 12 => 60, 13 => 65, 14 => 65 ,15 => 70, 16 => 70, 17 => 75, 18 => 75, 19 => 75,
                        20 => 80, 21 => 80 , 22 => 85, 23 => 85,
                        'default' => 86,
                    ],
                    '11'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 40, 4 => 40, 5 => 40, 6 => 45, 7 => 45, 8 => 50, 9 => 50,
                        10 => 50, 11 => 55 , 12 => 55, 13 => 60, 14 => 60 ,15 => 65, 16 => 65, 17 => 65, 18 => 70, 19 => 70,
                        20 => 75, 21 => 75 , 22 => 75, 23 => 80,
                        'default' => 81,
                    ],
                    '12'=>[
                        0 => 29, 1 => 30, 2 => 35, 3 => 35, 4 => 35, 5 => 40, 6 => 40, 7 => 45, 8 => 45, 9 => 50,
                        10 => 50, 11 => 55 , 12 => 55, 13 => 55, 14 => 60, 15 => 60, 16 => 65, 17 => 65, 18 => 70, 19 => 70,
                        20 => 70, 21 => 75 , 22 => 75, 23 => 80,
                        'default' => 81,
                    ],
                    '13'=>[
                        0 => 29, 1 => 30, 2 => 35, 3 => 35, 4 => 40, 5 => 40, 6 => 40, 7 => 45, 8 => 45, 9 => 50,
                        10 => 50, 11 => 50 , 12 => 55, 13 => 55, 14 => 60, 15 => 60, 16 => 65, 17 => 65, 18 => 65, 19 => 70,
                        20 => 70, 21 => 75 , 22 => 75, 23 => 75,
                        'default' => 76,
                    ],
                    '14'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 35, 4 => 40, 5 => 40, 6 => 45, 7 => 45, 8 => 45, 9 => 50,
                        10 => 50, 11 => 55 , 12 => 55, 13 => 55, 14 => 60 ,15 => 60, 16 => 65, 17 => 65, 18 => 70, 19 => 70,
                        20 => 70, 21 => 75 , 22 => 75, 23 => 80,
                        'default' => 81,
                    ],
                    '15'=>[
                        0 => 34, 1 => 35, 2 => 35, 3 => 40, 4 => 40, 5 => 40, 6 => 45, 7 => 45, 8 => 45, 9 => 50,
                        10 => 50, 11 => 50 , 12 => 55, 13 => 55, 14 => 55 ,15 => 60, 16 => 60, 17 => 60, 18 => 65, 19 => 65,
                        20 => 65, 21 => 70 , 22 => 70, 23 => 75,
                        'default' => 76,
                    ],
                ],
                '掩饰(L)' => [
                    '7'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 5, 7 => 10, 8 => 15, 9 => 15,
                        10 => 20, 11 => 25, 12 => 30, 13 => 35, 14 => 35, 15 => 40, 16 => 45, 17 => 50, 18 => 50, 19 => 55,
                        20 => 60, 21 => 65, 22 => 70,
                        'default' => 71,
                    ],
                    '8'=>[
                        0 => 0, 1 => 5, 2 => 10, 3 => 10, 4 => 15, 5 => 15, 6 => 20, 7 => 20, 8 => 25, 9 => 30,
                        10 => 30, 11 => 35, 12 => 35, 13 => 40, 14 => 40, 15 => 45, 16 => 50, 17 => 50, 18 => 55, 19 => 55,
                        20 => 60, 21 => 60, 22 => 65,
                        'default' => 66,
                    ],
                    '9'=>[
                        0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 5 ,5 => 10, 6 => 10, 7 => 15, 8 => 20, 9 => 20,
                        10 => 25, 11 => 30 , 12 => 30, 13 => 35, 14 => 40 ,15 => 40, 16 => 45, 17 => 50, 18 => 50, 19 => 55,
                        20 => 60, 21 => 60 , 22 => 65,
                        'default' => 66,
                    ],
                    '10'=>[
                        0 => 14, 1 => 15, 2 => 15, 3 => 20, 4 => 20 ,5 => 25, 6 => 25, 7 => 30, 8 => 30, 9 => 35,
                        10 => 35, 11 => 35 , 12 => 40, 13 => 40, 14 => 45 ,15 => 45, 16 => 50, 17 => 50, 18 => 55, 19 => 55,
                        20 => 60, 21 => 60 , 22 => 65,
                        'default' => 66,
                    ],
                    '11'=>[
                        0 => 24, 1 => 25, 2 => 25, 3 => 25, 4 => 30 ,5 => 30, 6 => 35, 7 => 35, 8 => 35, 9 => 40,
                        10 => 40, 11 => 40 , 12 => 45, 13 => 45, 14 => 50 ,15 => 50, 16 => 50, 17 => 55, 18 => 55, 19 => 60,
                        20 => 60, 21 => 60, 22 => 65,
                        'default' => 66,
                    ],
                    '12'=>[
                        0 => 18, 1 => 20, 2 => 25, 3 => 25, 4 => 25 ,5 => 30, 6 => 30, 7 => 35, 8 => 35, 9 => 40,
                        10 => 40, 11 => 45 , 12 => 45, 13 => 50, 14 => 50 ,15 => 55, 16 => 55, 17 => 60, 18 => 60, 19 => 60,
                        20 => 65, 21 => 65 , 22 => 70,
                        'default' => 71,
                    ],
                    '13'=>[
                        0 => 24, 1 => 25, 2 => 25, 3 => 25, 4 => 30 ,5 => 30, 6 => 35, 7 => 35, 8 => 40, 9 => 40,
                        10 => 40, 11 => 45 , 12 => 45, 13 => 50, 14 => 50 ,15 => 50, 16 => 55, 17 => 55, 18 => 60, 19 => 60,
                        20 => 60, 21 => 65 , 22 => 65,
                        'default' => 66,
                    ],
                    '14'=>[
                        0 => 19, 1 => 20, 2 => 20, 3 => 25, 4 => 25 ,5 => 30, 6 => 30, 7 => 35, 8 => 35, 9 => 40,
                        10 => 40, 11 => 45 , 12 => 45, 13 => 50, 14 => 50 ,15 => 55, 16 => 55, 17 => 60, 18 => 60, 19 => 65,
                        20 => 65, 21 => 70 , 22 => 70,
                        'default' => 71,
                    ],
                    '15'=>[
                        0 => 19, 1 => 20, 2 => 20, 3 => 25, 4 => 25 ,5 => 30, 6 => 30, 7 => 35, 8 => 35, 9 => 40,
                        10 => 40, 11 => 45 , 12 => 45, 13 => 50, 14 => 50 ,15 => 55, 16 => 55, 17 => 60, 18 => 60, 19 => 65,
                        20 => 65, 21 => 70 , 22 => 70,
                        'default' => 71,
                    ],
                ],
            ],
        ];
        // 获取用户性别,年龄
        $UserModel = new UserModel();
        $info = $UserModel->where('id','=', $uid)->field('age,sex')->find();
        $sexKey = ($info['sex'] == 1) ? 'male' : 'female'; //性别:male男，
        if($info['age'] == null){
            $ageKey = 7;
        }elseif($info['age'] >= 0 && $info['age']<=7){
            $ageKey = 7;
        }elseif($info['age'] >= 15){
            $ageKey = 15;
        }else{
            $ageKey = $info['age'];
        }
        // 根据映射数组转换分数
        if ($score !== '' && isset($scoreMappings[$sexKey][$name][$ageKey])) {
            $mapping = $scoreMappings[$sexKey][$name][$ageKey];
            $score = (int)$score;
            return $mapping[$score] ?? $mapping['default'] ?? 70;
        }
        return null; // 或者根据实际情况返回其他默认值或处理方式
    }


    public function formula21($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $str = substr($formula,0,1);
        if($str == 's'){
            $score = 0;
            foreach ($relatedQuestionArr as $value) {
                $score += $questionScoreArr[$value['num']]['score'];
            }
            //第一个因子（L）到（Q）
            switch ($formula){
                case 'sum(15,30,45,60,75,90,105,120,135,150,165,195,225,255,285)':
                    //说谎（L）
                    $name = "说谎(L)";
                    break;
                case 'sum(14,17,20,27,31,34,35,40,42,48,49,50,53,54,56,65,66,75,83,85,112,113,115,121,123,139,146,151,156,164,168,169,177,184,185,196,197,199,200,202,205,206,209,210,211,215,218,220,227,245,246,247,252,256,257,258,269,272,275,276,286,288,291,293)':
                    //诈病（F）
                    $name = "诈病（F）";
                    break;
                case 'sum(30,39,71,89,96,124,129,134,138,142,148,160,170,171,180,183,217,234,267,272,296,316,322,368,370,372,373,375,386,394)':
                    //校正（K）
                    $name = "校正（K）";
                    break;
                case 'sum(2,3,7,9,18,23,29,43,51,55,62,63,68,72,103,108,114,125,130,153,155,161,163,175,188,189,190,192,230,243,273,274,281)':
                    //疑病(Hs)
                    $name = "疑病(Hs)";
                    break;
                case 'sum(2,5,8,9,18,30,32,36,39,41,43,46,51,52,57,58,64,67,80,86,88,89,95,98,104,107,122,130,131,138,142,145,152,153,154,155,158,159,160,178,182,189,191,193,207,208,233,236,241,242,248,259,263,270,271,272,285,286,288,290)':
                    //抑郁(D)
                    $name = "抑郁(D)";
                    break;
                case 'sum(2,3,6,7,8,9,10,12,23,26,30,32,43,44,47,51,55,71,76,89,93,103,107,109,114,124,128,129,136,137,141,147,153,160,162,163,170,172,174,175,179,180,186,188,189,190,192,201,213,230,234,238,243,253,265,267,274,279,289,292)':
                    //癔病(Hy)
                    $name = "癔病(Hy)";
                    break;
                case 'sum(8,16,20,21,24,32,33,35,37,38,42,61,67,82,84,91,94,96,102,106,107,110,118,127,134,137,141,155,170,171,173,180,183,201,215,216,224,231,235,237,239,244,245,248,267,284,287,289,294,296)':
                    //精神病态(Pd)
                    $name = "精神病态(Pd)";
                    break;
                case 'sum(1,4,19,25,26,28,69,70,74,77,78,79,80,81,87,89,92,99,112,115,116,117,120,126,132,133,134,140,144,149,176,179,187,198,203,204,213,214,217,219,221,223,226,229,231,239,249,254,260,261,262,264,278,280,282,283,295,297,299,300)':
                    //男女性化（Mf）
                    $name = "男女性化（Mf）";
                    break;
                case 'sum(16,24,27,35,93,107,109,110,111,117,121,123,124,127,151,157,158,202,268,275,281,284,291,293,294,299,305,313,314,316,317,319,326,327,338,341,347,348,364,365)':
                    //妄想(Pa)
                    $name = "妄想(Pa)";
                    break;
                case 'sum(3,8,10,15,22,32,36,41,67,76,86,94,102,106,122,142,152,159,164,178,182,189,217,238,266,301,304,321,329,336,337,340,342,343,344,346,349,351,352,353,356,357,358,359,360,361,362,366)':
                    //精神衰弱(Pt)
                    $name = "精神衰弱(Pt)";
                    break;
                case 'sum(15,17,22,40,41,47,52,65,76,97,103,104,119,121,156,157,159,168,177,178,179,182,187,192,194,196,202,210,212,220,238,241,251,259,266,273,276,281,282,291,297,301,302,303,306,307,308,309,310,311,312,315,318,320,322,323,324,325,328,330,331,332,333,334,335,339,341,345,349,350,352,354,355,356,360,363,364,366)':
                    //精神分裂(Sc)
                    $name = "精神分裂(Sc)";
                    break;
                case 'sum(11,13,21,22,59,64,73,97,100,101,105,109,111,119,120,127,134,143,148,156,157,166,167,171,180,181,194,212,222,226,228,232,233,238,240,250,251,263,266,267,268,271,277,279,289,298)':
                    //轻躁狂(Ma)
                    $name = "轻躁狂(Ma)";
                    break;
                case 'sum(25,32,33,57,67,82,91,99,111,117,119,124,126,138,143,147,171,172,180,193,201,208,229,231,236,254,262,267,278,281,292,296,304,309,316,321,332,336,342,353,357,359,367,369,370,371,373,374,376,377,378,379,380,381,382,383,384,385,387,388,389,390,391,392,393,395,396,397,398,399)':
                    //社会内向(Si)
                    $name = "社会内向(Si)";
                    break;
                case 'sum(1===399)':
                    //疑问(Q)
                    $name = "疑问(Q)";
                    break;
                case 'sum(13,14,23,31,32,43,67,86,125,142,158,186,191,217,238,241,263,301,317,321,322,335,337,340,352,361,397,418,424,431,439,442,499,506,530,449,555,7,18,107,163,190,230,242,264,287,371,407,523,528)':
                    //显性焦虑(MAS)
                    $name = "显性焦虑(MAS)";
                    break;
                case 'sum(19,21,24,41,63,67,70,82,86,98,100,138,141,158,165,180,189,201,212,236,239,259,267,304,305,321,337,338,343,357,361,362,375,382,383,390,394,397,398,408,443,487,488,489,509,531,549,554,564)':
                    //依赖性(Dy)
                    $name = "依赖性(Dy)";
                    break;
                case 'sum(64,229,255,270,368,432,523,32,61,82,86,94,186,223,224,240,249,250,267,268,304,343,356,395,419,483,558,562)':
                    //支配性(Do)
                    $name = "支配性(Do)";
                    break;
                case 'sum(58,111,173,221,294,412,501,552,6,28,30,33,56,116,118,157,175,181,223,224,260,304,419,434,437,468,469,471,472,529,553,558)':
                    //社会责任感(Re)
                    $name = "社会责任感(Re)";
                    break;
                case 'sum(6,20,30,56,67,105,116,134,145,162,169,181,225,236,238,285,296,319,337,382,411,418,436,446,447,460,529,555,58,80,92,96,111,167,174,220,242,249,250,291,313,360,378,439,444,483,488,489,527,548)':
                    //控制(Cn)
                    $name = "控制(Cn)";
                    break;
            }
            $scored = $this->getConvertedScore21($uid,$score,$name);
            return (float)number_format($scored, 2);
        }else{
            //最后一个因子（重复题）
            $array = $relatedQuestionArr;
            $result = [];
            // 遍历原始数组，每两项为一组
            for ($i = 0; $i < count($array); $i += 2) {
                if (isset($array[$i + 1])) { // 确保存在成对的元素
                    $result[] = [$array[$i], $array[$i + 1]];
                } else { // 如果没有成对的元素，可以选择处理剩余的元素
                    $result[] = [$array[$i]];
                }
            }
            //判断每一组里的选项是否一致，一致为0分。不一致为1分。超过6分认为无效。
            $score = 0;
            foreach ($result as $value) {
                $temp_score = 0;
                foreach($value as $v){
                    $temp_score += $questionScoreArr[$v['num']]['score'];
                }
                if($temp_score == 1){
                    //表示选项不一致记1分
                    $score += 1;
                }
            }
            return (float)number_format($score, 2);
        }
    }


    private function getConvertedScore21($uid, $score,$name)
    {
//        var_dump($name);die;
//        var_dump($score);die;
        // 合并的映射数组
        $scoreMappings = [
            'male' => [
                '说谎(L)' => [
                    0 => 27, 1 => 31, 2 => 35, 3 => 39, 4 => 43,
                    5 => 47, 6 => 51, 7 => 55, 8 => 59, 9 => 63,
                    10 => 67, 11 => 71, 12 => 75, 13 => 78, 14 => 82,15 => 86,
                    'default' => 87,
                ],
                '诈病（F）' => [
                    0 => 30, 1 => 31, 2 => 32, 3 => 34, 4 => 35,5 => 37, 6 => 38, 7 => 40, 8 => 41, 9 => 43,
                    10 => 44, 11 => 46, 12 => 47, 13 => 49, 14 => 50,15 => 51, 16 => 53, 17 => 54, 18 => 56, 19 => 57,
                    20 => 59, 21 => 60, 22 => 62, 23 => 63, 24 => 65,25 => 66, 26 => 67, 27 => 69, 28 => 70, 29 => 72,
                    30 => 73, 31 => 75, 32 => 76, 33 => 78, 34 => 79,35 => 81, 36 => 82, 37 => 83, 38 => 85, 39 => 86,
                    40 => 88, 41 => 89, 42 => 91, 43 => 91, 44 => 94,45 => 95, 46 => 97, 47 => 98, 48 => 100, 49 => 101,
                    50 => 102, 51 => 104, 52 => 105, 53 => 107, 54 => 108,55 => 110, 56 => 111, 57 => 113, 58 => 114, 59 => 116,
                    60 => 117, 61 => 118,
                    'default' => 120,
                ],
                '校正（K）' => [
                    0 => 22, 1 => 24, 2 => 26, 3 => 28, 4 => 30,
                    5 => 32, 6 => 34, 7 => 37, 8 => 39, 9 => 41,
                    10 => 43, 11 => 45, 12 => 47, 13 => 50, 14 => 52,15 => 54, 16 => 56, 17 => 58, 18 => 60, 19 => 62,
                    20 => 65, 21 => 67, 22 => 69, 23 => 71, 24 => 73,25 => 75, 26 => 77, 27 => 80, 28 => 82, 29 => 84,30 => 86,
                    'default' => 87,
                ],
                '疑病(Hs)' => [
                    0 => 31, 1 => 33, 2 => 35, 3 => 37, 4 => 39,
                    5 => 42, 6 => 44, 7 => 46, 8 => 48, 9 => 80,
                    10 => 52, 11 => 54, 12 => 56, 13 => 58, 14 => 60,15 => 63, 16 => 65, 17 => 67, 18 => 69, 19 => 71,
                    20 => 73, 21 => 75, 22 => 77, 23 => 79, 24 => 82,25 => 84, 26 => 86, 27 => 88, 28 => 90, 29 => 92,
                    30 => 94, 31 => 96, 32 => 98, 33 => 100,
                    'default' => 101,
                ],
                '抑郁(D)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0,
                    10 => 0, 11 => 0, 12 => 21, 13 => 23, 14 => 25,15 => 27, 16 => 29, 17 => 31, 18 => 33, 19 => 35,
                    20 => 37, 21 => 39, 22 => 41, 23 => 43, 24 => 45,25 => 47, 26 => 49, 27 => 51, 28 => 53, 29 => 55,
                    30 => 57, 31 => 59, 32 => 61, 33 => 63, 34 => 65,35 => 67, 36 => 69, 37 => 71, 38 => 73, 39 => 75,
                    40 => 77, 41 => 79, 42 => 81, 43 => 83, 44 => 85,45 => 87, 46 => 89, 47 => 91, 48 => 93, 49 => 95,
                    50 => 97, 51 => 99, 52 => 101, 53 => 104, 54 => 106,55 => 108, 56 => 110, 57 => 112, 58 => 114, 59 => 116,
                    60 => 118,
                    'default' => 119,
                ],
                '癔病(Hy)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 21, 8 => 23, 9 => 25,
                    10 => 27, 11 => 29, 12 => 31, 13 => 33, 14 => 34,15 => 36, 16 => 38, 17 => 40, 18 => 42, 19 => 44,
                    20 => 46, 21 => 48, 22 => 49, 23 => 51, 24 => 53,25 => 55, 26 => 57, 27 => 59, 28 => 61, 29 => 62,
                    30 => 64, 31 => 66, 32 => 68, 33 => 70, 34 => 72,35 => 74, 36 => 75, 37 => 77, 38 => 79, 39 => 81,
                    40 => 83, 41 => 85, 42 => 87, 43 => 89, 44 => 90,45 => 92, 46 => 94, 47 => 96, 48 => 98, 49 => 100,
                    50 => 102, 51 => 103, 52 => 105, 53 => 107, 54 => 109,55 => 111, 56 => 113, 57 => 115, 58 => 117, 59 => 118,
                    'default' => 120,
                ],
                '精神病态(Pd)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 20, 7 => 22, 8 => 24, 9 => 27,
                    10 => 29, 11 => 31, 12 => 33, 13 => 36, 14 => 38,15 => 40, 16 => 43, 17 => 45, 18 => 47, 19 => 50,
                    20 => 52, 21 => 54, 22 => 56, 23 => 59, 24 => 61,25 => 63, 26 => 66, 27 => 68, 28 => 70, 29 => 72,
                    30 => 75, 31 => 77, 32 => 79, 33 => 82, 34 => 84,35 => 86, 36 => 89, 37 => 91, 38 => 93, 39 => 95,
                    40 => 98, 41 => 100, 42 => 102, 43 => 105, 44 => 107,45 => 109, 46 => 111, 47 => 114, 48 => 116, 49 => 118,
                    'default' => 119,
                ],
                '男女性化（Mf）' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0,
                    10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0,15 => 0, 16 => 21, 17 => 23, 18 => 26, 19 => 28,
                    20 => 31, 21 => 33, 22 => 36, 23 => 38, 24 => 41,25 => 43, 26 => 46, 27 => 48, 28 => 51, 29 => 53,
                    30 => 56, 31 => 58, 32 => 60, 33 => 63, 34 => 65,35 => 68, 36 => 70, 37 => 73, 38 => 75, 39 => 78,
                    40 => 80, 41 => 83, 42 => 85, 43 => 88, 44 => 90,45 => 93, 46 => 95, 47 => 98, 48 => 100, 49 => 103,
                    50 => 105, 51 => 108, 52 => 110, 53 => 112, 54 => 115,55 => 117,
                    'default' => 120,
                ],
                '妄想(Pa)' => [
                    0 => 19, 1 => 21, 2 => 22, 3 => 24, 4 => 27, 5 => 30, 6 => 32, 7 => 35, 8 => 37, 9 => 40,
                    10 => 42, 11 => 45, 12 => 47, 13 => 50, 14 => 52,15 => 55, 16 => 58, 17 => 60, 18 => 63, 19 => 65,
                    20 => 68, 21 => 40, 22 => 73, 23 => 75, 24 => 78,25 => 81, 26 => 83, 27 => 86, 28 => 88, 29 => 91,
                    30 => 93, 31 => 96, 32 => 98, 33 => 101, 34 => 103,35 => 106, 36 => 109, 37 => 111, 38 => 114, 39 => 116,40 => 119,
                    'default' => 69,
                ],
                '精神衰弱(Pt)' => [
                    0 => 27, 1 => 28, 2 => 30, 3 => 31, 4 => 32,
                    5 => 33, 6 => 35, 7 => 36, 8 => 37, 9 => 38,
                    10 => 40, 11 => 41, 12 => 42, 13 => 43, 14 => 45,15 => 46, 16 => 47, 17 => 48, 18 => 50, 19 => 51,
                    20 => 52, 21 => 53, 22 => 55, 23 => 56, 24 => 57,25 => 59, 26 => 60, 27 => 61, 28 => 62, 29 => 64,
                    30 => 65, 31 => 66, 32 => 67, 33 => 69, 34 => 70,35 => 71, 36 => 72, 37 => 74, 38 => 75, 39 => 76,
                    40 => 77, 41 => 79, 42 => 80, 43 => 81, 44 => 82,45 => 84, 46 => 85, 47 => 86, 48 => 88, 49 => 89,
                    'default' => 90,
                ],
                '精神分裂(Sc)' => [
                    0 => 27, 1 => 28, 2 => 29, 3 => 30, 4 => 31,
                    5 => 32, 6 => 33, 7 => 34, 8 => 35, 9 => 36,
                    10 => 37, 11 => 38, 12 => 39, 13 => 40, 14 => 41,15 => 42, 16 => 43, 17 => 44, 18 => 45, 19 => 46,
                    20 => 47, 21 => 48, 22 => 49, 23 => 49, 24 => 50,25 => 51, 26 => 52, 27 => 53, 28 => 54, 29 => 55,
                    30 => 56, 31 => 57, 32 => 58, 33 => 59, 34 => 60,35 => 61, 36 => 62, 37 => 63, 38 => 64, 39 => 65,
                    40 => 66, 41 => 67, 42 => 68, 43 => 69, 44 => 70,45 => 71, 46 => 72, 47 => 73, 48 => 74, 49 => 75,
                    50 => 76, 51 => 77, 52 => 78, 53 => 79, 54 => 80,55 => 81, 56 => 82, 57 => 83, 58 => 84, 59 => 85,
                    60 => 86, 61 => 87, 62 => 88, 63 => 89, 64 => 90,65 => 91, 66 => 92, 67 => 93, 68 => 94, 69 => 95,
                    70 => 90, 71 => 97, 72 => 98, 73 => 99, 74 => 100,75 => 101, 76 => 102, 77 => 103, 78 => 104,
                    'default' => 105,
                ],
                '轻躁狂(Ma)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 20, 4 => 22,5 => 24, 6 => 26, 7 => 28, 8 => 30, 9 => 31,
                    10 => 33, 11 => 35, 12 => 37, 13 => 39, 14 => 41,15 => 43, 16 => 45, 17 => 47, 18 => 49, 19 => 50,
                    20 => 52, 21 => 54, 22 => 56, 23 => 58, 24 => 60,25 => 62, 26 => 64, 27 => 66, 28 => 68, 29 => 70,
                    30 => 71, 31 => 73, 32 => 75, 33 => 77, 34 => 79,35 => 81, 36 => 83, 37 => 85, 38 => 87, 39 => 89,
                    40 => 90, 41 => 92, 42 => 94, 43 => 96, 44 => 98,45 => 100, 46 => 102,
                    'default' => 103,
                ],
                '社会内向(Si)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0,
                    10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 20, 15 => 21, 16 => 23, 17 => 24, 18 => 26, 19 => 27,
                    20 => 28, 21 => 30, 22 => 31, 23 => 33, 24 => 34, 25 => 36, 26 => 37, 27 => 39, 28 => 40, 29 => 41,
                    30 => 43, 31 => 44, 32 => 46, 33 => 47, 34 => 49, 35 => 50, 36 => 52, 37 => 53, 38 => 55, 39 => 56,
                    40 => 57, 41 => 59, 42 => 60, 43 => 62, 44 => 63, 45 => 65, 46 => 66, 47 => 68, 48 => 69, 49 => 71,
                    50 => 72, 51 => 73, 52 => 75, 53 => 76, 54 => 78, 55 => 79, 56 => 81, 57 => 82, 58 => 84, 59 => 95,
                    60 => 87, 61 => 88, 62 => 89, 63 => 91, 64 => 92, 65 => 94, 66 => 95, 67 => 97, 68 => 98, 69 => 100,70 => 101,
                    'default' => 102,
                ],
                '疑问(Q)' => [
                    0 => 43, 1 => 44, 2 => 44, 3 => 12, 4 => 46,
                    5 => 47, 6 => 47, 7 => 48, 8 => 48, 9 => 49,
                    10 => 49, 11 => 50, 12 => 51, 13 => 51, 14 => 52,15 => 53, 16 => 53, 17 => 54, 18 => 54, 19 => 55,
                    20 => 56, 21 => 56, 22 => 57, 23 => 58, 24 => 58,25 => 59, 26 => 59, 27 => 60, 28 => 61, 29 => 61,
                    30 => 62,31 => 63, 32 => 63, 33 => 64, 34 => 65,35 => 65, 36 => 66, 37 => 66, 38 => 67, 39 => 68,
                    40 => 68, 41 => 69, 42 => 70, 43 => 70, 44 => 71,45 => 71, 46 => 72, 47 => 73, 48 => 73, 49 => 74,
                    50 => 75, 51 => 75, 52 => 76, 53 => 76, 54 => 77,55 => 78, 56 => 78, 57 => 79, 58 => 80, 59 => 80,60 => 81,
                    'default' => 82,
                ],
                '显性焦虑(MAS)' => [
                    0 => 24, 1 => 26, 2 => 27, 3 => 28, 4 => 30, 5 => 31, 6 => 32, 7 => 34, 8 => 35, 9 => 36,
                    10 => 38, 11 => 38, 12 => 40, 13 => 42, 14 => 43,15 => 44, 16 => 46, 17 => 47, 18 => 48, 19 => 50,
                    20 => 51, 21 => 52, 22 => 54, 23 => 55, 24 => 56,25 => 58, 26 => 59, 27 => 60, 28 => 62, 29 => 63,
                    30 => 64,31 => 66, 32 => 67, 33 => 68, 34 => 70,35 => 71, 36 => 73, 37 => 74, 38 => 75, 39 => 77,
                    40 => 78, 41 => 79, 42 => 81, 43 => 82, 44 => 83,45 => 85, 46 => 86, 47 => 87, 48 => 89, 49 => 90,
                    50 => 91,
                    'default' => 92,
                ],
                '依赖性(Dy)' => [
                    0 => 0, 1 => 0, 2 => 20, 3 => 21, 4 => 22,5 => 23, 6 => 25, 7 => 26, 8 => 27, 9 => 28,
                    10 => 30, 11 => 31, 12 => 32, 13 => 33, 14 => 34,15 => 36, 16 => 37, 17 => 38, 18 => 39, 19 => 41,
                    20 => 42, 21 => 43, 22 => 44, 23 => 46, 24 => 57,25 => 48, 26 => 49, 27 => 51, 28 => 52, 29 => 53,
                    30 => 54,31 => 56, 32 => 57, 33 => 58, 34 => 59,35 => 61, 36 => 62, 37 => 63, 38 => 64, 39 => 66,
                    40 => 67, 41 => 68, 42 => 69, 43 => 71, 44 => 72,45 => 73, 46 => 74, 47 => 75, 48 => 77, 49 => 78,
                    50 => 79, 51 => 80, 52 => 82, 53 => 83, 54 => 84,55 => 85, 56 => 87, 57 => 88,
                    'default' => 89,
                ],
                '支配性(Do)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 23, 8 => 26, 9 => 29,
                    10 => 32, 11 => 35, 12 => 39, 13 => 42, 14 => 45,15 => 48, 16 => 51, 17 => 55, 18 => 58, 19 => 61,
                    20 => 64, 21 => 67, 22 => 77, 23 => 74, 24 => 77,25 => 80, 26 => 84, 27 => 87, 28 => 90,
                    'default' => 91,
                ],
                '社会责任感(Re)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 22,
                    10 => 24, 11 => 26, 12 => 29, 13 => 31, 14 => 34,15 => 36, 16 => 39, 17 => 41, 18 => 43, 19 => 46,
                    20 => 48, 21 => 51, 22 => 53, 23 => 55, 24 => 58,25 => 60, 26 => 63, 27 => 65, 28 => 68, 29 => 70,
                    30 => 72,31 => 75, 32 => 77,
                    'default' => 78,
                ],
                '控制(Cn)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0,
                    10 => 0, 11 => 0, 12 => 0,13 => 0, 14 => 20,15 => 22, 16 => 25, 17 => 28, 18 => 30, 19 => 33,
                    20 => 36, 21 => 38, 22 => 41, 23 => 43, 24 => 46,25 => 49, 26 => 51, 27 => 54, 28 => 57, 29 => 59,
                    30 => 62,31 => 65, 32 => 67, 33 => 70, 34 => 73,35 => 75, 36 => 78, 37 => 81, 38 => 83, 39 => 86,
                    40 => 89, 41 => 91, 42 => 95, 43 => 97, 44 => 99,45 => 102, 46 => 105, 47 => 107, 48 => 110, 49 => 113,
                    50 => 115,
                    'default' => 116,
                ],
            ],
            'female' => [
                '说谎(L)' => [
                    0 => 27, 1 => 31, 2 => 35, 3 => 39, 4 => 43,
                    5 => 47, 6 => 51, 7 => 55, 8 => 59, 9 => 63,
                    10 => 67, 11 => 71, 12 => 75, 13 => 79, 14 => 83,15 => 87,
                    'default' => 88,
                ],
                '诈病（F）' => [
                    0 => 27,  1 => 28,   2 => 30,  3 => 32, 4 => 34, 5 => 36,  6 => 38,  7 => 40,  8 => 42,  9 => 44,
                    10 => 46, 11 => 48, 12 => 50, 13 => 52, 14 => 54,15 => 56, 16 => 58, 17 => 60, 18 => 62, 19 => 64,
                    20 => 66, 21 => 68, 22 => 70, 23 => 72, 24 => 74,25 => 76, 26 => 78, 27 => 80, 28 => 82, 29 => 84,
                    30 => 86, 31 => 88, 32 => 90, 33 => 92, 34 => 94,35 => 96, 36 => 98, 37 => 100, 38 => 102, 39 => 104,
                    40 => 106, 41 => 108, 42 => 110, 43 => 112, 44 => 114,45 => 116, 46 => 118,
                    'default' => 120,
                ],
                '校正（K）' => [
                    0 => 21, 1 => 23, 2 => 25, 3 => 28, 4 => 30,
                    5 => 32, 6 => 35, 7 => 37, 8 => 40, 9 => 42,
                    10 => 44, 11 => 47, 12 => 49, 13 => 51, 14 => 54,15 => 56, 16 => 58, 17 => 61, 18 => 63, 19 => 65,
                    20 => 68, 21 => 70, 22 => 72, 23 => 75, 24 => 77,25 => 79, 26 => 82, 27 => 84, 28 => 86, 29 => 89,30 => 91,
                    'default' => 92,
                ],
                '疑病(Hs)' => [
                    0 => 30,  1 => 32,   2 => 34,  3 => 36, 4 => 38, 5 => 40,  6 => 42,  7 => 44,  8 => 46,  9 => 48,
                    10 => 50, 11 => 52, 12 => 54, 13 => 56, 14 => 58,15 => 60, 16 => 62, 17 => 64, 18 => 66, 19 => 68,
                    20 => 70, 21 => 72, 22 => 74, 23 => 76, 24 => 75,25 => 80, 26 => 82, 27 => 84, 28 => 86, 29 => 88,
                    30 => 90, 31 => 92, 32 => 94, 33 => 96,
                    'default' => 97,
                ],
                '抑郁(D)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0,
                    10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 21,15 => 23, 16 => 25, 17 => 27, 18 => 29, 19 => 31,
                    20 => 33, 21 => 35, 22 => 37, 23 => 39, 24 => 41,25 => 43, 26 => 45, 27 => 47, 28 => 49, 29 => 51,
                    30 => 53, 31 => 55, 32 => 57, 33 => 59, 34 => 61,35 => 63, 36 => 65, 37 => 67, 38 => 69, 39 => 71,
                    40 => 73, 41 => 75, 42 => 76, 43 => 78, 44 => 80,45 => 82, 46 => 84, 47 => 86, 48 => 88, 49 => 90,
                    50 => 92, 51 => 94, 52 => 96, 53 => 98, 54 => 100,55 => 102, 56 => 104, 57 => 106, 58 => 108, 59 => 110,
                    60 => 112,
                    'default' => 113,
                ],
                '癔病(Hy)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 21, 8 => 23, 9 => 25,
                    10 => 26, 11 => 28, 12 => 30, 13 => 32, 14 => 34,15 => 35, 16 => 37, 17 => 39, 18 => 41, 19 => 43,
                    20 => 44, 21 => 46, 22 => 48, 23 => 50, 24 => 52,25 => 53, 26 => 55, 27 => 57, 28 => 59, 29 => 61,
                    30 => 62, 31 => 64, 32 => 66, 33 => 68, 34 => 70,35 => 71, 36 => 73, 37 => 75, 38 => 77, 39 => 79,
                    40 => 81, 41 => 82, 42 => 84, 43 => 86, 44 => 88,45 => 90, 46 => 91, 47 => 93, 48 => 95, 49 => 97,
                    50 => 99, 51 => 100, 52 => 102, 53 => 104, 54 => 106,55 => 108, 56 => 109, 57 => 111, 58 => 113, 59 => 115,
                    60 => 117,
                    'default' => 118,
                ],
                '精神病态(Pd)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 20, 6 => 22, 7 => 24, 8 => 26, 9 => 29,
                    10 => 31, 11 => 33, 12 => 35, 13 => 38, 14 => 40,15 => 42, 16 => 44, 17 => 47, 18 => 49, 19 => 51,
                    20 => 53, 21 => 56, 22 => 58, 23 => 60, 24 => 62,25 => 65, 26 => 67, 27 => 69, 28 => 71, 29 => 74,
                    30 => 76, 31 => 78, 32 => 80, 33 => 83, 34 => 85,35 => 87, 36 => 89, 37 => 92, 38 => 94, 39 => 96,
                    40 => 98, 41 => 101, 42 => 103, 43 => 105, 44 => 107,45 => 110, 46 => 112, 47 => 114, 48 => 116, 49 => 119,
                    'default' => 120,
                ],
                '男女性化（Mf）' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 120, 6 => 117, 7 => 114, 8 => 112, 9 => 109,
                    10 => 107, 11 => 104, 12 => 101, 13 => 99, 14 => 96,15 => 94, 16 => 91, 17 => 88, 18 => 86, 19 => 83,
                    20 => 81, 21 => 78, 22 => 76, 23 => 73, 24 => 70,25 => 67, 26 => 65, 27 => 63, 28 => 60, 29 => 57,
                    30 => 55, 31 => 52, 32 => 50, 33 => 47, 34 => 44,35 => 42, 36 => 39, 37 => 37, 38 => 34, 39 => 31,
                    40 => 29, 41 => 26, 42 => 24, 43 => 21,
                    'default' => 20,
                ],
                '妄想(Pa)' => [
                    0 => 19, 1 => 20, 2 => 22, 3 => 25, 4 => 28, 5 => 30, 6 => 33, 7 => 35, 8 => 38, 9 => 40,
                    10 => 43, 11 => 45, 12 => 48, 13 => 50, 14 => 53,15 => 56, 16 => 58, 17 => 61, 18 => 63, 19 => 66,
                    20 => 68, 21 => 71, 22 => 73, 23 => 76, 24 => 78,25 => 81, 26 => 84, 27 => 86, 28 => 89, 29 => 91,
                    30 => 94, 31 => 96, 32 => 99, 33 => 101, 34 => 104,35 => 106, 36 => 109, 37 => 112, 38 => 114, 39 => 117,40 => 119,
                    'default' => 69,
                ],
                '精神衰弱(Pt)' => [
                    0 => 25, 1 => 27, 2 => 28, 3 => 29, 4 => 31,
                    5 => 32, 6 => 33, 7 => 34, 8 => 35, 9 => 36,
                    10 => 38, 11 => 40, 12 => 41, 13 => 42, 14 => 43,15 => 45, 16 => 46, 17 => 47, 18 => 49, 19 => 50,
                    20 => 51, 21 => 52, 22 => 54, 23 => 55, 24 => 56,25 => 57, 26 => 59, 27 => 60, 28 => 61, 29 => 63,
                    30 => 64, 31 => 65, 32 => 66, 33 => 68, 34 => 69,35 => 70, 36 => 72, 37 => 73, 38 => 74, 39 => 75,
                    40 => 77, 41 => 78, 42 => 79, 43 => 80, 44 => 82,45 => 83, 46 => 84, 47 => 86, 48 => 87, 49 => 88,
                    'default' => 89,
                ],
                '精神分裂(Sc)' => [
                    0 => 26, 1 => 27, 2 => 28, 3 => 29, 4 => 30,
                    5 => 31, 6 => 32, 7 => 33, 8 => 34, 9 => 35,
                    10 => 36, 11 => 37, 12 => 39, 13 => 39, 14 => 40,15 => 41, 16 => 42, 17 => 43, 18 => 45, 19 => 46,
                    20 => 47, 21 => 48, 22 => 49, 23 => 50, 24 => 51,25 => 52, 26 => 53, 27 => 54, 28 => 55, 29 => 56,
                    30 => 57, 31 => 58, 32 => 59, 33 => 60, 34 => 62,35 => 63, 36 => 64, 37 => 65, 38 => 66, 39 => 67,
                    40 => 68, 41 => 69, 42 => 70, 43 => 71, 44 => 72,45 => 73, 46 => 74, 47 => 75, 48 => 76, 49 => 77,
                    50 => 78, 51 => 79, 52 => 80, 53 => 81, 54 => 82,55 => 83, 56 => 85, 57 => 86, 58 => 87, 59 => 87,
                    60 => 89, 61 => 90, 62 => 91, 63 => 92, 64 => 93,65 => 94, 66 => 95, 67 => 96, 68 => 97, 69 => 98,
                    70 => 99, 71 => 100, 72 => 101, 73 => 102, 74 => 103,75 => 104, 76 => 105, 77 => 106, 78 => 107,
                    'default' => 108,
                ],
                '轻躁狂(Ma)' => [
                    0 => 0, 1 => 0, 2 => 21, 3 => 23, 4 => 25, 5 => 27, 6 => 29, 7 => 31, 8 => 33, 9 => 35,
                    10 => 37, 11 => 39, 12 => 41, 13 => 42, 14 => 44,15 => 46, 16 => 48, 17 => 50, 18 => 52, 19 => 54,
                    20 => 56, 21 => 58, 22 => 60, 23 => 62, 24 => 64,25 => 66, 26 => 68, 27 => 70, 28 => 72, 29 => 73,
                    30 => 75, 31 => 77, 32 => 79, 33 => 81, 34 => 83,35 => 85, 36 => 87, 37 => 89, 38 => 91, 39 => 93,
                    40 => 95, 41 => 97, 42 => 99, 43 => 101, 44 => 103, 45 => 104, 46 => 106,
                    'default' => 107,
                ],
                '社会内向(Si)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0,
                    10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 21, 19 => 22,
                    20 => 24, 21 => 25, 22 => 27, 23 => 28, 24 => 30, 25 => 31, 26 => 33, 27 => 34, 28 => 36, 29 => 37,
                    30 => 39, 31 => 40, 32 => 42, 33 => 43, 34 => 45, 35 => 46, 36 => 48, 37 => 49, 38 => 51, 39 => 52,
                    40 => 54, 41 => 55, 42 => 57, 43 => 58, 44 => 60, 45 => 61, 46 => 63, 47 => 64, 48 => 65, 49 => 67,
                    50 => 68, 51 => 70, 52 => 71, 53 => 73, 54 => 74, 55 => 76, 56 => 77, 57 => 79, 58 => 80, 59 => 82,
                    60 => 83, 61 => 85, 62 => 86, 63 => 88, 64 => 89, 65 => 91, 66 => 92, 67 => 94, 68 => 95, 69 => 97,70 => 98,
                    'default' => 99,
                ],
                '疑问(Q)' => [
                    0 => 41, 1 => 42, 2 => 42, 3 => 43, 4 => 44,
                    5 => 45, 6 => 46, 7 => 47, 8 => 47, 9 => 48,
                    10 => 48, 11 => 50, 12 => 51, 13 => 52, 14 => 52,15 => 53, 16 => 54, 17 => 55, 18 => 56, 19 => 57,
                    20 => 57, 21 => 58, 22 => 59, 23 => 60, 24 => 61,25 => 61, 26 => 62, 27 => 63, 28 => 64, 29 => 65,
                    30 => 66,
                    'default' => 67,
                ],
                '显性焦虑(MAS)' => [
                    0 => 22, 1 => 23, 2 => 24, 3 => 26, 4 => 27,5 => 29, 6 => 30, 7 => 31, 8 => 33, 9 => 34,
                    10 => 35, 11 => 37, 12 => 38, 13 => 39, 14 => 41,15 => 42, 16 => 43, 17 => 45, 18 => 46, 19 => 48,
                    20 => 49, 21 => 50, 22 => 52, 23 => 53, 24 => 54,25 => 56, 26 => 57, 27 => 58, 28 => 60, 29 => 61,
                    30 => 63,31 => 64, 32 => 65, 33 => 67, 34 => 68,35 => 69, 36 => 71, 37 => 72, 38 => 73, 39 => 75,
                    40 => 76, 41 => 77, 42 => 79, 43 => 80, 44 => 82,45 => 83, 46 => 84, 47 => 86, 48 => 87, 49 => 88,
                    50 => 90,
                    'default' => 91,
                ],
                '依赖性(Dy)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 20, 8 => 22, 9 => 23,
                    10 => 24, 11 => 26, 12 => 27, 13 => 28, 14 => 30,15 => 31, 16 => 32, 17 => 34, 18 => 35, 19 => 36,
                    20 => 37, 21 => 39, 22 => 40, 23 => 41, 24 => 43,25 => 44, 26 => 45, 27 => 47, 28 => 48, 29 => 49,
                    30 => 51,31 => 52, 32 => 53, 33 => 55, 34 => 56,35 => 57, 36 => 59, 37 => 60, 38 => 61, 39 => 62,
                    40 => 64, 41 => 65, 42 => 66, 43 => 68, 44 => 69,45 => 70, 46 => 72, 47 => 73, 48 => 74, 49 => 76,
                    50 => 77, 51 => 78, 52 => 80, 53 => 81, 54 => 82,55 => 84, 56 => 85, 57 => 86,
                    'default' => 87,
                ],
                '支配性(Do)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 20, 8 => 24, 9 => 27,
                    10 => 31, 11 => 35, 12 => 38, 13 => 42, 14 => 46,15 => 49, 16 => 53, 17 => 56, 18 => 60, 19 => 64,
                    20 => 67, 21 => 71, 22 => 75, 23 => 79, 24 => 82,25 => 85, 26 => 89, 27 => 93, 28 => 96,
                    'default' => 97,
                ],
                '社会责任感(Re)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0,
                    10 => 0, 11 => 0, 12 => 0, 13 => 21, 14 => 25,15 => 28, 16 => 31, 17 => 34, 18 => 39, 19 => 41,
                    20 => 44, 21 => 47, 22 => 50, 23 => 53, 24 => 57,25 => 60, 26 => 63, 27 => 66, 28 => 69, 29 => 73,
                    30 => 76,31 => 79, 32 => 82,
                    'default' => 83,
                ],
                '控制(Cn)' => [
                    0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0,5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0,
                    10 => 0, 11 => 0, 12 => 0,13 => 0, 14 => 20,15 => 23, 16 => 25, 17 => 28, 18 => 30, 19 => 33,
                    20 => 35, 21 => 39, 22 => 42, 23 => 44, 24 => 47,25 => 50, 26 => 53, 27 => 55, 28 => 58, 29 => 61,
                    30 => 63,31 => 66, 32 => 69, 33 => 72, 34 => 74,35 => 77, 36 => 80, 37 => 82, 38 => 85, 39 => 88,
                    40 => 90, 41 => 93, 42 => 96, 43 => 99, 44 => 101,45 => 104, 46 => 107, 47 => 109, 48 => 112, 49 => 115,
                    50 => 117,
                    'default' => 118,
                ],
            ],
        ];
        // 获取用户性别
        $UserModel = new UserModel();
        $sex = $UserModel->where('id','=', $uid)->value('sex');
        $sexKey = ($sex == 1) ? 'male' : 'female';
        // 获取分数
        // 根据映射数组转换分数
        if ($score !== '' && isset($scoreMappings[$sexKey][$name])) {
            $mapping = $scoreMappings[$sexKey][$name];
            $score = (int)$score;
            return $mapping[$score] ?? $mapping['default'] ?? 70;
        }
        return null; // 或者根据实际情况返回其他默认值或处理方式
    }

    public function formula11($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        $positive_factor_score = 0;//总积极因素
        $negative_factor_score = 0;//总消极因素
        foreach ($relatedQuestionArr as $value) {
            switch ($value['num']){
                case 13:
                case 14:
                case 21:
                case 24:
                case 25:
                case 4:
                case 9:
                case 15:
                case 17:
                case 19:
                case 1:
                case 8:
                case 16:
                case 30:
                    $positive_factor_score += $questionScoreArr[$value['num']]['score'];
                    break;
                case 2:
                case 6:
                case 10:
                case 11:
                case 12:
                case 29:
                case 7:
                case 20:
                case 26:
                case 28:
                case 5:
                case 22:
                case 27:
                case 3:
                case 18:
                case 23:
                    $negative_factor_score += $questionScoreArr[$value['num']]['score'];
                    break;
            }
        }
        $score = 128+$positive_factor_score-$negative_factor_score;
        return (float)number_format($score, 2);
    }

    public function formula13($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        //最后一个因子（重复题）
        $array = $relatedQuestionArr;
        $result = [];
        // 遍历原始数组，每两项为一组
        for ($i = 0; $i < count($array); $i += 2) {
            if (isset($array[$i + 1])) { // 确保存在成对的元素
                $result[] = [$array[$i], $array[$i + 1]];
            } else { // 如果没有成对的元素，可以选择处理剩余的元素
                $result[] = [$array[$i]];
            }
        }
        //判断每一组里的选项是否一致，一致为0分。不一致为1分。超过6分认为无效。
        $score = 0;
        foreach ($result as $value) {
            $temp_name = '';
            foreach($value as $v){
                if($temp_name == ''){
                    $temp_name = $questionScoreArr[$v['num']]['name'];
                }else{
                    if($temp_name != $questionScoreArr[$v['num']]['name']){
                        $score +=1;
                    }
                }
            }
        }
        return (float)number_format($score, 2);
    }

    public function formula14($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value) {
            $score += $questionScoreArr[$value['num']]['score'];
        }
        $score = (20-$score)*2;
        return (float)number_format($score, 2);
    }

    public function formula15($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $scoreOne = 0;
        $scoreTwo = 0;
        $scoreThree = 0;
        foreach ($relatedQuestionArr as $value) {
            switch ($value['num']){
                case 1:
                    $scoreOne += $questionScoreArr[$value['num']]['score'];
                    break;
                case 2:
                case 3:
                case 4:
                case 12:
                case 13:
                    $scoreTwo += $questionScoreArr[$value['num']]['score'];
                    break;
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                    $scoreThree += $questionScoreArr[$value['num']]['score'];
                    break;
            }
        }
        $score = ($scoreOne*4)+($scoreTwo*2)+($scoreThree);
        return (float)number_format($score, 2);
    }

    public function formula16($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        $scoreOne = 0;
        foreach ($relatedQuestionArr as $value) {
            switch ($value['num']){
                case 1:
                case 2:
                case 3:
                    if($scoreOne<$questionScoreArr[$value['num']]['score']){
                        $scoreOne = $questionScoreArr[$value['num']]['score'];
                    }
                    break;
                default:
                    $score += $questionScoreArr[$value['num']]['score'];
                    break;
            }
        }
        $score = $score+$scoreOne;
        return (float)number_format($score, 2);
    }

    public function formula17($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $positiveScore = 0;//阳性项目数
        foreach ($relatedQuestionArr as $value) {
            if($questionScoreArr[$value['num']]['score'] >=2 && $questionScoreArr[$value['num']]['score'] <=4){
                $positiveScore += 1;
            }
        }
        $score = $positiveScore;
        return (float)number_format($score, 2);
    }

    public function formula18($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value) {
            $score += $questionScoreArr[$value['num']]['score'];
        }
        $score = (20-$score)*2;
        return (float)number_format($score, 2);
    }

    public function formula19($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        $positive_factor_score = 0;//因子一：8，30题目
        $negative_factor_score = 0;//因子二：1,16题目
        foreach ($relatedQuestionArr as $value) {
            switch ($value['num']){
                case 8:
                case 30:
                    $positive_factor_score += $questionScoreArr[$value['num']]['score'];
                    break;
                case 1:
                case 16:
                    $negative_factor_score += $questionScoreArr[$value['num']]['score'];
                    break;
            }
        }
        $score = (8+$positive_factor_score-$negative_factor_score)*2;
        return (float)number_format($score, 2);
    }

    public function formula20($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $title_count = count($relatedQuestionArr);
        $score = 0;
        foreach ($relatedQuestionArr as $value) {
            $score += $questionScoreArr[$value['num']]['score'];
        }
        $score = ($score/$title_count)*100;
        return round($score);
    }


    public function formula101($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value){
            switch ($value['num']){
                case 93:
                case 6:
                    $score += abs($questionScoreArr[6]['score']-$questionScoreArr[93]['score']);
                    break;
                case 11:
                case 80:
                    $score += abs($questionScoreArr[11]['score']-$questionScoreArr[80]['score']);
                    break;
                case 15:
                case 84:
                    $score += abs($questionScoreArr[15]['score']-$questionScoreArr[84]['score']);
                    break;
                case 24:
                case 58:
                    $score += abs($questionScoreArr[24]['score']-$questionScoreArr[58]['score']);
                    break;
                case 32:
                case 90:
                    $score += abs($questionScoreArr[32]['score']-$questionScoreArr[90]['score']);
                    break;
            }
        }
        return (float)number_format($score, 2);
    }

    public function formula102($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        $num = 0;
        $score2 = 0;
        $num2 = 0;
        foreach ($relatedQuestionArr as $value){
            if ($value['num'] < 13){
                $score += $questionScoreArr[$value['num']]['score'];
                $num++;
            }else{
                $score2 += $questionScoreArr[$value['num']]['score'];
                $num2++;
            }
        }
        return (float)number_format(($score/$num)-($score2/$num2), 2);
    }

    public function formula103($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value){
            switch ($value['num']){
                case 9:
                case 37:
                    $score += abs($questionScoreArr[9]['score']-$questionScoreArr[37]['score']);
                    break;
                case 15:
                case 42:
                    $score += abs($questionScoreArr[15]['score']-$questionScoreArr[42]['score']);
                    break;
                case 25:
                case 47:
                    $score += abs($questionScoreArr[25]['score']-$questionScoreArr[47]['score']);
                    break;
                case 7:
                case 53:
                    $score += abs($questionScoreArr[7]['score']-$questionScoreArr[53]['score']);
                    break;
            }
        }
        return (float)number_format($score, 2);
    }

    public function formula104($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value){
            switch ($value['num']){
                case 2:
                case 13:
                    $score += abs($questionScoreArr[2]['score']-$questionScoreArr[13]['score']);
                    break;
            }
        }
        return (float)number_format($score, 2);
    }

    public function formula105($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value){
            switch ($value['num']){
                case 3:
                case 39:
                    $score += abs($questionScoreArr[3]['score']-$questionScoreArr[39]['score']);
                    break;
                case 9:
                case 47:
                    $score += abs($questionScoreArr[9]['score']-$questionScoreArr[47]['score']);
                    break;
                case 15:
                case 63:
                    $score += abs($questionScoreArr[15]['score']-$questionScoreArr[63]['score']);
                    break;
            }
        }
        return (float)number_format($score, 2);
    }

    public function formula106($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = 0;
        foreach ($relatedQuestionArr as $value){
            switch ($value['num']){
                case 5:
                case 20:
                    $score += abs($questionScoreArr[5]['score']-$questionScoreArr[20]['score']);
                    break;
                case 4:
                case 24:
                    $score += abs($questionScoreArr[4]['score']-$questionScoreArr[24]['score']);
                    break;
            }
        }
        return (float)number_format($score, 2);
    }

    public function formula201($relatedQuestionArr, $questionScoreArr, $formula,$uid): float
    {
        $score = $questionScoreArr[3]['score']/$questionScoreArr[4]['score'];
        return (float)number_format($score, 2);
    }


}